package com.mxchip.livestarmobile.mobile.ui.contact

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.mxchip.livestarmobile.R
import com.mxchip.livestarmobile.mobile.db.entity.Contact
import com.mxchip.livestarmobile.mobile.ui.ItemHolder
import kotlinx.android.synthetic.main.list_item_contact.*

class ContactRecyclerAdapter(private val onClickListener: ((View, Contact) -> Unit)? = null) : RecyclerView.Adapter<ItemHolder>()  {

    var data: List<Contact> = emptyList()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        val view = LayoutInflater.from(parent.context)
                .inflate(R.layout.list_item_contact, parent, false)
        return ItemHolder(view)
    }

    override fun getItemCount(): Int {
        return data.size
    }

    override fun onBindViewHolder(holder: ItemHolder, position: Int) {
        holder.text_name.text = data[position].fullName
        holder.containerView.setOnClickListener {
            onClickListener?.invoke(it, data[position])
        }
    }

}